package com.quanyan.place.service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.place.entity.TbBizPlaceMember;
import com.quanyan.place.entity.TbBizPlaceMemberCard;
import com.quanyan.place.entity.TbBizPlaceMemberCardExample;
import com.quanyan.place.entity.TbBizPlaceMemberCardType;
import com.quanyan.place.entity.TbBizPlaceMemberOpHistory;
import com.quanyan.place.entity.TbBizPlaceOrder;
import com.quanyan.place.entity.apireq.ReqMemberCardOperate;
import com.quanyan.place.entity.apireq.ReqMemberCardType;
import com.quanyan.place.entity.apireq.ReqOrderHistory;
import com.quanyan.place.entity.apireq.ReqOrderOperate;
import com.quanyan.place.entity.apiresp.RespCardPayList;
import com.quanyan.place.entity.apiresp.RespMemberCard;
import com.quanyan.place.entity.apiresp.RespMemberCardInfo;
import com.quanyan.place.entity.apiresp.RespMemberCardOperate;
import com.quanyan.place.entity.apiresp.RespMemberCardType;
import com.quanyan.place.entity.apiresp.RespPlaceInfo;
import com.quanyan.place.entity.apiresp.RespPlaceMemberCard;
import com.quanyan.place.entity.apiresp.RespPlaceMemberCardDetail;
import com.quanyan.place.entity.vo.PlaceMemberTypeVo;
import com.quanyan.place.entity.vo.ReqPlaceMemberSearch;

/**
 * Created by youxiaojia on 2016/8/23.
 * 场馆会员Service
 */
public interface PlaceMemberService {
    /**
     * 按要求填入信息增加储值折扣卡/次卡会员类型
     * @param reqMemberType
     * @return
     */
    APIResponse insertMemberType(ReqMemberCardType reqMemberType);
    /**
     * 编辑会员类型
     * @param reqMemberType
     * @return
     */
    APIResponse updateMemberType(ReqMemberCardType reqMemberType);

    /**
     * 更新会员卡类型名称，会员卡类型描述
     * @param memberCardTypeName
     * @param memberCardTypeDescription
     * @return
     */
    APIResponse updateMemberTypeNameAndDescription(Integer memberCardTypeId,String memberCardTypeName,String memberCardTypeDescription,
                                                   Double discount,BigDecimal giveAmount,BigDecimal initAmount);

    /**
     * 分页获取会员类型列表
     * @return
     */
    APIResponse<PageObj<List<RespMemberCardType>>> queryMemberTypeListByConditions(PlaceMemberTypeVo placeMemberTypeVo);

    /**
     * 获取会员类型详情
     * @param id
     * @return
     */
    APIResponse getMemberTypeDetailById(Integer id);

    /**
     * 删除会员类型
     * @param id
     * @return
     */
    APIResponse delMemberTypeById(Integer id);

    /**
     * 启用,禁用会员类型
     * @param id
     * @param status
     * @return
     */
    APIResponse updateMemberTypeStatusById(Integer id,byte status);
    /**
     * 获取会员卡字典
     * @return
     */
    APIResponse<?> getMemberTypeDictDisplayName();

    /**
     * 根据用户名，电话获取会员Uid
     * @param userName
     * @param phone
     * @return
     */
    Integer getUidByNameAndPhone(String userName, String phone);

    /**
     * 开单获取用户所有相关会员卡
     */
    APIResponse<List<RespMemberCard>> billingPlaceGetMemberCardList(String userName, String phone, Integer placeId,Integer categoryId);
    
    /**
     * 开单根据手机号、姓名模糊查询获取用户所有相关会员卡
     */
    APIResponse<List<RespMemberCardInfo>> queryMemberCardList(String key, Integer placeId,Integer categoryId);

    /**
     * 购物车获取会员卡列表
     */
//    APIResponse<List<RespMemberCard>> shoppingCardGetMemberCardList(String userName, String phone, Integer placeId,Integer categoryId);
    APIResponse<List<RespMemberCard>> shoppingCardGetMemberCardList(String userName, String phone, Integer placeId);

    /**
     * 商品售卖会员卡消费获取用户所有相关会员卡
     */
    APIResponse<List<RespPlaceMemberCard>> goodsConsumeGetMemberCardList(String userName, String phone, Integer placeId, Integer categoryId);


    /**
     * 根据会员卡id获取会员卡
     * @param id
     * @return
     */
    TbBizPlaceMemberCard getTbBizPlaceMemberCardById(Integer id);

    /**
     * 判断是否为场馆会员
     * @param uid
     * @param placeId
     * @param categoryId
     * @return
     */
    boolean isPlaceMember(Integer uid,Integer placeId,Integer categoryId,Integer source);



    /**
     * 获取用户场馆的会员卡信息
     * @param uid
     * @param placeId
     * @param categoryId
     * @return
     */
    List<TbBizPlaceMemberCard> getPlaceMemberInfo(Integer uid, Integer placeId,Integer categoryId,boolean isNeedNumberCard);

    /**
     * 根据会员卡类型ID获取会员卡类型
     * @param cardTypeId
     * @return
     */
    TbBizPlaceMemberCardType getMemberTypeById(Integer cardTypeId);

    void addPlaceMember(TbBizPlaceMember member);

    /**
     * 增加会员卡
     * @param memberCard
     */
    void addPlaceMemberCard(TbBizPlaceMemberCard memberCard);

    boolean isExistsMemberCard(Integer placeId,Integer cardTypeId, Integer uid);

    /**
     * 根据手机号查询会员信息
     * @param phone
     * @return
     */
    TbBizPlaceMember getPlaceMember(String phone);

    /**
     * 根据会员id查询会员信息
     * @param memberId
     * @return
     */
    TbBizPlaceMember getPlaceMemberById(Integer memberId);

    /**
     * 根据会员uid查询会员信息
     * @param memberUid
     * @return
     */
    TbBizPlaceMember getPlaceMemberByUid(Integer memberUid);

    /**
     * 是否包含会员卡
     * @param placeId
     * @return
     */
    boolean isPlaceContainMemberCard(Integer placeId);


    /**
     * 会员卡数目取得
     * @param keywords
     * @param placeId
     * @param cardType
     * @param status
     * @return
     */
    int countPlaceMemberCard(String keywords, Integer placeId, Integer cardType, Byte status,
                             Integer cityId,
                             String placeCode,
                             String placeName,
                             Byte orderType);

    /**
     * 查询会员卡列表
     * @param begin
     * @param pageSize
     * @param placeId
     * @param keywords
     * @param cardType
     * @param status
     * @param cityId
     * @param placeCode
     * @param placeName
     * @param orderType
     * @return
     */
    List<RespMemberCardInfo> selectMemberCardList(Integer begin,
                                                    Integer pageSize,
                                                    Integer placeId,
                                                    String keywords,
                                                    Integer cardType,
                                                    Byte status,
                                                    Integer cityId,
                                                    String placeCode,
                                                    String placeName,
                                                    Byte orderType);
    /**
     * 获取用户会员卡明细
     * @param reqMemberCardOperate
     * @return
     */
    APIResponse<PageObj<List<RespMemberCardOperate>>> getMemberCardOperateDetail(ReqMemberCardOperate reqMemberCardOperate);

    /**
     * 会员卡交易记录导出
     * @param reqMemberCardOperate
     * @return
     */
    List<RespMemberCardOperate> getMemberCardOperateDetailExport(ReqMemberCardOperate reqMemberCardOperate);
    /**
     * 获取卡信息
     * @param cardNo
     * @return
     */
    TbBizPlaceMemberCard getPlaceMemberCardInfo(String cardNo,Integer placeId,Integer uid);

    int updatePlaceMemberCardInfo(TbBizPlaceMemberCardExample tbBizPlaceMemberCardExample,TbBizPlaceMemberCard tbBizPlaceMemberCard);

     /**
     * 根据id获取会员操作详情
     * @param id
     * @return
     */
    APIResponse<?> getMemberCardOperateDetailById(Integer id);

    /**
     * 冻结会员
     * @param member
     * @return
     */
    APIResponse frozenMember(TbBizPlaceMember member);

    /**
     * 注销指定会员的所有会员卡
     * @param member
     * @return
     */
    APIResponse logOffMemberCardByMember(TbBizPlaceMember member);

    /**
     * 注销指定会员卡
     * @param tbBizPlaceMemberCard
     * @return
     */
    APIResponse logOffMemberCard(TbBizPlaceMemberCard tbBizPlaceMemberCard);

    /**
     * 挂失指定会员卡
     * @param memberCard
     * @return
     */
    APIResponse reportLossMemberCard(TbBizPlaceMemberCard memberCard);

    /**
     * 获取指定场馆会员卡类型
     * @param placeId
     * @return
     */
    List<TbBizPlaceMemberCardType> getMemberTypeByPlaceId(Integer placeId);

    void updatePlaceMemberCard(TbBizPlaceMemberCard memberCard);

    void updatePlaceMember(TbBizPlaceMember member);

    void addPlaceMemberCardOpRecord(TbBizPlaceMemberOpHistory opHistory);

    /*
     * 根据场馆id获取会员卡类型map
     * @param placeId
     * @return
     */
    APIResponse getMemberTypeNameByPlaceId(Integer placeId);

    APIResponse getMemberStatisticsByPlaceId(ReqMemberCardOperate reqMemberCardOperate);

    APIResponse getMemberTotalDataByPlaceId(ReqMemberCardOperate reqMemberCardOperate);

    APIResponse exportMemberStatisticsByPlaceId(ReqMemberCardOperate reqMemberCardOperate);

    List<TbBizPlaceMemberCardType> getMemberCardTypeListByPlaceId(Integer placeId, boolean isContainDisabled);


    TbBizPlaceMemberCard getCardInfoByMemberCardId(Integer memberCardId);

    int savePlaceMemberOpHistory(TbBizPlaceMemberOpHistory tbBizPlaceMemberOpHistory);

    List<TbBizPlaceMemberOpHistory> getMinDeadLineTimeByInnerCard(String  innerCardNo);

    /**
     * 根据手机号或电话模糊匹配会员信息
     */
    APIResponse queryPlaceMemberByPhoneOrName(Integer placeId, String phoneOrName);

    /**
     * 显示会员充值
     * @param cardID
     * @return
     */
    APIResponse<?> showCardRecharge(Integer cardID,Integer placeId);

    /**
     * 获取会员卡订单详情
     * @param placeId
     * @param cardTypeId
     * @return
     */
    APIResponse<?> getVipPayDetail(Integer placeId, Integer cardTypeId);

    /**
     * 获取用户会员卡信息
     * @param uid
     * @return
     */
    List<TbBizPlaceMemberCard> getTbBizPlaceMemberCardsByUid(Integer uid);

    /**
     * 转换用户会员卡信息
     * @param map
     * @return
     */
    APIResponse<List<RespPlaceMemberCardDetail>> getRespPlaceMemberCardDetail(Map<Integer, List<TbBizPlaceMemberCard>> map);

    /**
     * 购买会员卡-付费
     * @param userId
     * @param tbBizPlaceMemberCardType
     * @param payTypeId
     * @return
     */
    APIResponse<?> buyVenueVip(Integer userId, TbBizPlaceMemberCardType tbBizPlaceMemberCardType, Integer payTypeId, Integer platformType,Integer refereesId, Integer larkAppId);

    /**
     * 校验会员卡有效性
     * @param cardID
     * @return
     */
    APIResponse<?> vaildCardByID (Integer cardID,Integer placeId);

    /**
     * 分页查询会员交易记录
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    PageObj<List<TbBizPlaceMemberOpHistory>> getMemberOpHistory(Integer userId,TbBizPlaceMemberCard tbBizPlaceMemberCard,
                                                                Integer pageNum, Integer pageSize);

    /**
     * 根据用户id/卡类型id 获取用户会员卡信息
     * @param userId
     * @param cardTypeId
     * @return
     */
    TbBizPlaceMemberCard getTbBizPlaceMemberCardByTypeId(Integer userId, Integer cardTypeId);

    /**
     * app会员充值
     * @param userId
     * @param cardTypeId
     * @param payTypeId
     * @param tbBizPlaceMemberCard
     * @return
     */
    APIResponse<?> vipCardReChargeDetail(Integer userId, Integer cardTypeId, Integer payTypeId, TbBizPlaceMemberCard tbBizPlaceMemberCard, Integer platformType,Integer refereesId);

    List<RespCardPayList> getRespCardPayList(List<TbBizPlaceMemberOpHistory> list);

    /**
     * 订单取消
     * @param reqOrderOperate
     * @return
     */
    APIResponse<?> orderCancelOperate(ReqOrderOperate reqOrderOperate);

    /**
     * 订单成功
     * @param reqOrderOperate
     * @param tbBizPlaceOrder
     * @return
     */
    APIResponse<?> orderCompletePayOperate(ReqOrderOperate reqOrderOperate, TbBizPlaceOrder tbBizPlaceOrder);

    /**
     * 订单退款
     * @param reqOrderOperate
     * @param tbBizPlaceOrder
     * @return
     */
    APIResponse orderUnsubscribeOperate(ReqOrderOperate reqOrderOperate, TbBizPlaceOrder tbBizPlaceOrder);

    /**
     * 订单退款完成
     * @param reqOrderOperate
     * @param tbBizPlaceOrder
     * @return
     */
    APIResponse<?> orderCompleteUnsubscribeOperate(ReqOrderOperate reqOrderOperate, TbBizPlaceOrder tbBizPlaceOrder);

    /**
     * 订单退款受理成功
     * @param reqOrderOperate
     * @param tbBizPlaceOrder
     * @return
     */
    APIResponse<?> orderCancleToUnsubscribeOperate(ReqOrderOperate reqOrderOperate, TbBizPlaceOrder tbBizPlaceOrder);

    /**
     * 根据业务订单号查询
     * @param orderNo
     * @return
     */
    TbBizPlaceMemberOpHistory getTbBizPlaceMemberOpHistoryByOrderNo(String orderNo, Byte state);

    /**
     * 根据卡号查询会员卡
     * @param innerCardNo
     * @return
     */
    TbBizPlaceMemberCard getTbBizPlaceMemberCardByInnerCardNo(String innerCardNo);

    /**
     * 根据会员历史记录更新会员卡数据
     * @param placeOrderId
     * @return
     */
    APIResponse<?> updateMemberCardByHistory(String placeOrderId);

    /**
     * 增加会员卡
     * @param userId
     * @param tbBizPlaceMemberCardType
     * @param innerCardNo
     * @return
     */
    TbBizPlaceMemberCard addMemberCard(Integer userId, TbBizPlaceMemberCardType tbBizPlaceMemberCardType,
                                              String innerCardNo,Integer refereesId) throws Exception;

    /**
     * 根据会员历史记录增加会员卡数据
     * @param placeOrderId
     * @return
     */
    APIResponse<?> addMemberCardByHistory(String placeOrderId,Integer refereesId);

    /**
     * 导出会员列表类型
     * @param placeMemberTypeVo
     * @return
     */
    List<RespMemberCardType> queryMemberTypeListExport(PlaceMemberTypeVo placeMemberTypeVo);

    /**
     * 查询指定uid是否在当前场馆会员表中存在
     * @param uid
     * @return
     */
    boolean isExistsPlaceMember(Integer uid);


    /**
     * 注销会员卡历史记录
     * @param tbBizPlaceMemberCard
     * @param userId
     * @param createUid
     * @param platform
     * @return
     */
    TbBizPlaceMemberOpHistory addLogOffMemberCardByHistory(TbBizPlaceMemberCard tbBizPlaceMemberCard,
                                                           Integer userId, Integer createUid, Integer platform);

    /**
     * 会员卡记录流水表对象转换订单历史表对象
     * @param tbBizPlaceMemberOpHistory
     * @return
     */
    ReqOrderHistory tbBizPlaceMemberOpHistory2ReqOrderHistory(TbBizPlaceMemberOpHistory tbBizPlaceMemberOpHistory);

    int countPlaceMemberCard(ReqPlaceMemberSearch reqMemberSearch);

    List<RespMemberCardInfo> selectMemberCardList(ReqPlaceMemberSearch reqMemberSearch);

    /**
     * 查询指定场馆互通会员的场馆列表
     * @param placeId
     * @param vipShareNo
     * @return
     */
    List<RespPlaceInfo> getSharePlace(Integer placeId, String vipShareNo, boolean isFilterPlaceId);

    /**
     * 检查场馆是否共享会员
     * @param placeId
     * @return
     */
    boolean checkIsShareVip(Integer placeId);

    /**
     * 通过指定场馆查询共享会员场馆集合
     * @param placeId
     * @return
     */
    List<Integer> getShareVipPlaceIds(Integer placeId);

    /**
     * 通过指定vipShareNo查询共享会员场馆集合
     * @param vipShareNo
     * @return
     */
    List<Integer> getSharePlaceIdsByVipShareNo(String vipShareNo);

    void updatePlaceAttachBatch(String vipShareNo, List<Integer> placeIds);

    /**
     * 批量将线上场馆支持会员卡场馆导入到redis
     */
    APIResponse<?> updateSupportMemberPlaceBatch();
    
    /**
     * 转移会员卡
     * @param memberCardNo
     * @param mobile
     * @param userId
     */
    void  transferMemberCard(String memberCardNo, String mobile, Integer userId);
    
}
